﻿using System;
using System.Collections.Generic;
using System.Text;
using HAVNet.Intros.Parsing;


namespace HAVNet.Intros.AST
{
    // event EventHandler Pipo = null, Papo = null;
    // o...
    // event EventHandler Pipo { add { ... } remove {...} };

    public abstract class ASTMemberDeclEvent : ASTMemberDeclStruct
    {
        protected string smods()
        {
            string mods = "";

            if (Mods.has(modifiers, Mods.newMod         )) mods += "new ";

            if (Mods.has(modifiers, Mods.publicMod      )) mods += "public ";
            if (Mods.has(modifiers, Mods.protectedMod   )) mods += "protected ";
            if (Mods.has(modifiers, Mods.internalMod    )) mods += "internal ";
            if (Mods.has(modifiers, Mods.privateMod     )) mods += "private ";

            if (Mods.has(modifiers, Mods.unsafeMod      )) mods += "unsafe ";
            if (Mods.has(modifiers, Mods.staticMod      )) mods += "static ";
            if (Mods.has(modifiers, Mods.virtualMod     )) mods += "virtual ";
            if (Mods.has(modifiers, Mods.sealedMod      )) mods += "sealed ";

            if (Mods.has(modifiers, Mods.overrideMod    )) mods += "override ";
            if (Mods.has(modifiers, Mods.abstractMod    )) mods += "abstract ";
            if (Mods.has(modifiers, Mods.externMod      )) mods += "extern ";

            return mods;
        }

        protected string attrs()
        {
            return ((null == _attrGroups) ? "" : _attrGroups.ToString() + Environment.NewLine);
        }
    }

    public class ASTMemberDeclEventNormal : ASTMemberDeclEvent
    {
        public ASTType type { get; set; }
        public readonly ASTVariableDeclarators  variableDeclarators = new ASTVariableDeclarators();

        public override string ToString()
        {
            return
                attrs() +
                smods() +
                "event " +
                type.ToString() + " " +
                variableDeclarators.ToString() + ";" + Environment.NewLine;
        }
    }

    public class ASTMemberDeclEventAccessors : ASTMemberDeclEvent
    {
        public          ASTType                 type            { get; set; }
        public          ASTTypeName             typeName        { get; set; }
        public readonly ASTAccessorEvents   accessorDecls   = new ASTAccessorEvents();

        public override string ToString()
        {
            return
                attrs() +
                smods() +
                "event " +
                type.ToString() + " " +
                typeName.ToString() + Environment.NewLine +
                "{" + Environment.NewLine + accessorDecls.ToString() + Environment.NewLine + "}" + Environment.NewLine;
        }
    }
}
